package  
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.net.URLRequest;
	import ginger.geom.RectangleShape;
	import caurina.transitions.Tweener;
	import flash.events.Event;
	
	/**
	 * 
	 * @author
	 */
	public class ActionObject extends Sprite
	{
		
		
		/**
		 * 在建立对象的时候，需要传递控制器进来
		 * @param	ctrl
		 */
		private var _gap:Number = 10;
		private var _width:Number = 250;
		private var _height:Number = 150;
		private var _box:Sprite;
		private var _item1:PhotoItem;
		private var _item2:ButtonPhotoItem;
		
		public static const OVER:String = 'actionOver';
		public static const OUT:String = 'actionOut';
		
		public function ActionObject(data1:PhotoVO,data2:PhotoVO) 
		{
			_box = new Sprite();
			addChild(_box);
			_item1 = new PhotoItem(_width, _height, 0, 0,data1);
			_item2 = new ButtonPhotoItem(_width, _height, 0, _height + _gap, data2);
			_item1.addEventListener(ActionObject.OVER, onOver);
			_item1.addEventListener(ActionObject.OUT, onOut);
			_item2.addEventListener(ActionObject.OVER, onOver);
			_item2.addEventListener(ActionObject.OUT, onOut);
			
			
			_box.addChild(_item1);
			_box.addChild(_item2);
			
			
			_box.x=-_item1.width/2;
			_box.y = -(_item1.height + _item2.height + _gap) / 2;
			this.mouseEnabled = false;
 		}
	
		public function onOver(evt:Event):void
		{
			var item:PhotoItem = evt.target as PhotoItem;
			if (item == _item1)
			    Tweener.addTween(_item2, { time:1.5, alpha:.3 } );
			else 
			    Tweener.addTween(_item1, { time:1.5, alpha:.3 } );
			dispatchEvent(evt.clone());
		}
		
		public function onOut(evt:Event):void
		{
			var item:PhotoItem = evt.target as PhotoItem;
			if (item == _item1)
			    Tweener.addTween(_item2, { time:1.5, alpha:1 } );
			else 
			    Tweener.addTween(_item1, { time:1.5, alpha:1 } );
            dispatchEvent(evt.clone());
		}
	}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import caurina.transitions.Tweener;
import flash.display.Loader;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.display.Bitmap;
class PhotoItem extends Sprite
{
	private var _posX:Number;
	private var _posY:Number;
	private var _width:Number;
	private var _height:Number;
	private var _loader:Loader;
	private var _link:String;
	protected var box:Sprite;
	public function PhotoItem(width:Number,height:Number,posX:Number,posY:Number,data:PhotoVO)
	{
		box = new Sprite();
		addChild(box);
		_width = width;
		_height = height;
		
		box.graphics.beginFill(0, 0.5);
		box.graphics.drawRect(0, 0, width, height);
		box.graphics.endFill();
		
		box.addEventListener(MouseEvent.ROLL_OVER, onOver);
		box.addEventListener(MouseEvent.ROLL_OUT, onOut);
		
		this.x = _posX = posX;
		this.y = _posY = posY;
		
		this.buttonMode = true;
		_link = data.LINK;
		
		_loader = new Loader();
		_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
		_loader.load(new URLRequest(data.URL));
		addEventListener(MouseEvent.CLICK, onClick);
	}
	protected function onOver(evt:MouseEvent):void
	{
		var scale:Number = 1.1;
		var x:Number = _posX-_width * (scale-1) / 2;
		var y:Number = _posY-_height * (scale-1) / 2;
		Tweener.addTween(this, { time:1.5, x:x, y:y, scaleX:scale, scaleY:scale } );
		this.parent.swapChildrenAt(this.parent.getChildIndex(this), this.parent.numChildren - 1);
		dispatchEvent(new Event(ActionObject.OVER));
	}
	protected function onOut(evt:MouseEvent):void
	{
		Tweener.addTween(this, { time:1.5, x:_posX, y:_posY, scaleX:1, scaleY:1 } );
		dispatchEvent(new Event(ActionObject.OUT));
	}
	
	protected function onComplete(evt:Event):void
	{
		var bmp:Bitmap = evt.target.content as Bitmap;
		bmp.smoothing = true;
		box.addChild(bmp);
		bmp.alpha = 0;
		Tweener.addTween(bmp, { time:1, alpha:1 } );
	}
	private function onClick(evt:MouseEvent):void
	{
		navigateToURL(new URLRequest(_link));
	}
}
class ButtonPhotoItem extends PhotoItem
{
	private var _reflection:SWreflection;
	private var _posY:Number;
	public function ButtonPhotoItem(width:Number, height:Number, posX:Number, posY:Number, data:PhotoVO)
	{
		super(width, height, posX, posY, data);
		
		_reflection = new SWreflection(box, 120,.8);
		addChild(_reflection);
		_posY = posY;
		
		_reflection.y = posY-7;
		_reflection.x = posX;
		_reflection.mouseEnabled = _reflection.mouseChildren = false;
	}
	override protected function onComplete(evt:Event):void 
	{
		var bmp:Bitmap = evt.target.content as Bitmap;
		super.onComplete(evt);
		_reflection.updateTarget(bmp);
		_reflection.y = _posY-7;
	}
}